var app = getApp(),
    util = require("../../../utils/util.js");

const date = new Date();
const yearList = [];
const monthList = [];
for (let i = 1990; i <= date.getFullYear(); i++) {
    yearList.push(i)
}

for (let i = 1; i <= 12; i++) {
    monthList.push(i)
}

Page({
    data: {
        yearList: yearList,
        monthList: monthList,
        month: 1,
        value: [9999, date.getMonth()],
        lists: [],
    },
    onLoad: function(t) {
        var e = this,
            mm = parseInt(date.getMonth()) + 1;
        mm = mm < 10 ? '0' + mm : mm;
        app.setNavigationBarColor(e);
        e.setData({
            start_time: date.getFullYear() + "-" + mm,
            start_timeText: date.getFullYear() + "年" + mm + "月",
        })
        e.getDeal();
    },
    onShow: function() {
        if (wx.getStorageSync("isSJJYQKOnShow")) {
            this.ConfirmPricker();
        }
        wx.setStorageSync("isSJJYQKOnShow", false)
    },
    getDeal: function() {
        wx.showLoading({
            title: '加载中'
        })
        var a = this,
            n = wx.getStorageSync("sjdsjid"),
            o = this.data.start_time;
        app.util.request({
            url: "entry/wxapp/GetStoreZjtj",
            cachetime: "0",
            data: {
                store_id: n,
                time: o,
            },
            success: function(t) {
                var e = t.data;
                a.setData({
                    lists: e.list,
                    deal_money: e.total_money,
                    deal_num: e.total
                });
                wx.hideLoading();
            },
            complete: function(t) {
                wx.hideLoading();
            }
        });
    },
    // 选择时间
    ShowPricker: function() {
        this.setData({
            isShowPricker: true,
        })
    },
    bindChange: function(e) {
        let val = e.detail.value;
        let mm = this.data.monthList[val[1]];
        mm = mm < 10 ? '0' + mm : mm;
        this.setData({
            start_time: this.data.yearList[val[0]] + "-" + mm,
            start_timeText: this.data.yearList[val[0]] + "年" + mm + "月",
        });
    },
    ClosePricker: function() {
        this.setData({
            isShowPricker: false,
        })
    },
    ConfirmPricker: function() {
        this.setData({
            isShowPricker: false,
            lists: [],
        });
        this.getDeal();
    },
});